package com.dhwl.hsh.driver.ui.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dhwl.hsh.lib.view.spinnerloading.SpinnerLoading;
import com.dhwl.hsh.driver.R;

/**
 * 进度条加载对话框
 *
 * @author Derek.Kidd
 * @version V1.0.0
 * @date 2016-04-28 09:34
 */
public class LoadingDialogFragment extends DialogFragment {


    public final static String CANCELABLE = "cancelable";


    private boolean cancelable = true;


    private SpinnerLoading spinnerLoading;

    public static LoadingDialogFragment newInstance(boolean cancelable) {
        LoadingDialogFragment fragment = new LoadingDialogFragment();
        Bundle args = new Bundle();
        args.putBoolean(CANCELABLE, cancelable);
        fragment.setArguments(args);
        return fragment;
    }

    public static LoadingDialogFragment newInstance() {
        return newInstance(true);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cancelable = getArguments().getBoolean(CANCELABLE);
        setCancelable(cancelable);

        setStyle(DialogFragment.STYLE_NORMAL, R.style.loading_dialog);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.waiting_dialog_layout, container, false);
        spinnerLoading = (SpinnerLoading) v.findViewById(R.id.spinner_loading);
        getDialog().setCanceledOnTouchOutside(false);
        return v;
    }

}
